package com._520it.day1._07_preparedstatement;



import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;

import org.junit.Test;

import com._520it.util.JdbcUtil;

public class PreparedStatementTest {
 
	@Test
	public void testSaveByStatement() throws Exception {
		 String sql="INSERT INTO t_student(name,age) VALUES ('夕阳',43)";
		Connection conn = JdbcUtil.getConn();
		Statement st = conn.createStatement();
		st.executeUpdate(sql);//执行静态sql
		JdbcUtil.close(conn, st, null);
	}
	
	@Test
	public void testSaveByPreparedStatement() throws Exception {
		 String sql="INSERT INTO t_student(name,age) VALUES (?,?)";
		Connection conn = JdbcUtil.getConn();
		PreparedStatement ps=conn.prepareStatement(sql);
		//设置占位符参数
		ps.setString(1, "诺夏");
		ps.setInt(2, 24);
		ps.executeUpdate();
		JdbcUtil.close(conn, ps, null);
	}
}
